﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;

namespace Raider.WinForms.Actions.Utils
{
    static class DesignUtils
    {
        private static readonly HashSet<string> ProcessNames = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { 
            "devenv", "vcsexpress", "vbexpress", "vcexpress", "wdexpress", "sharpdevelop" };

        public static readonly bool RunningOnMono = Type.GetType("Mono.Runtime") != null;

        private static bool? designMode;
        public static bool DesignMode
        {
            get
            {
                if (designMode == null)
                {
                    designMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime ||
                                 ProcessNames.Contains(Process.GetCurrentProcess().ProcessName);
                }

                return designMode.GetValueOrDefault();
            }
        }

        public static string GetComponentName(IComponent component, string defaultNameValue)
        {
            string text = string.Empty;
            if (string.IsNullOrEmpty(defaultNameValue))
            {
                if (component.Site != null)
                {
                    text = component.Site.Name;
                }
                if (text == null)
                {
                    text = string.Empty;
                }
            }
            else
            {
                text = defaultNameValue;
            }
            return text;
        }
    }
}
